﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Pong_Project.Game_objects
{
    class PowerupManager
    {
        private static List<Powerup> activePowerups;
        private Bat batLeft, batRight;
        private Ball ball;

        public PowerupManager(Bat batLeft, Bat batRight, Ball ball)
        {
            activePowerups = new List<Powerup>();
            this.batLeft = batLeft;
            this.batRight = batRight;
            this.ball = ball;
        }

        public static void Add(Powerup powerup)
        {
            activePowerups.Add(powerup);
        }

        public static void Remove(Powerup powerup)
        {
            activePowerups.Remove(powerup);
        }

        public void Update(GameTime gameTime)
        {
            foreach (Powerup powerup in activePowerups)
            {
                if (powerup is PowerupBat)
                {
                    if (powerup.Intersects(batLeft))
                    {
                        powerup.ApplyEffect(batLeft);
                    }
                    else if (powerup.Intersects(batRight))
                    {
                        powerup.ApplyEffect(batRight);
                    }
                }
                else if (powerup is PowerupBall)
                {
                    if (powerup.Intersects(ball))
                    {
                        powerup.ApplyEffect(ball);
                    }
                }
                else
                {
                    throw new Exception("Invalid class type for powerup");
                }
            }
        }
    }
}
